package test1225;

public class Test02 {
    public static int m1(int[] arr) {
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        return max;
    }

    public static int m2(int[] arr) {
        int min = arr[0];
        for (int i = arr.length - 1; i >= 0; i--) {
            if (min == arr[i]) {
                return arr[i];
            }
        }
        return min;
    }

    public static double m3(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return (double) sum/arr.length;
    }

    public static void main(String[] args) {

        int[] arr = {1,2,3,4,5};

        // 返回最大值
        int max = m1(arr);
        System.out.println(max);

        // 返回最小值
        int min = m2(arr);
        System.out.println(min);

        // 返回平均值
        double avg = m3(arr);
        System.out.println(avg);

    }
}
